package com.wzx.user.controller;

import com.wzx.common.pojo.resp.Result;
import com.wzx.user.mongo.MsgDto;
import com.wzx.user.mongo.SystemMsg;
import com.wzx.user.mongo.req.GetMsg;
import com.wzx.user.mongo.req.SysMsgReq;
import com.wzx.user.pojo.MsgReq;
import com.wzx.user.service.mongo.MsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wzx
 * @version 1.0
 * @date 2022/7/27 - 16:31
 * @description 标题
 */
@Slf4j
@RestController
@RequestMapping("/msg")
@Api(tags = "消息管理")
public class MessageController {

    @Autowired
    private MsgService msgService;

    @ApiOperation(value = "获取与好友的消息")
    @PostMapping("/getMsgByUser")
    public Result getMsgByUser(@RequestBody GetMsg getMsgData) {
        return msgService.getMsgByUser(getMsgData);
    }

    @ApiOperation(value = "获取系统消息")
    @PostMapping("/getMsgBySystem")
    public Result getMsgBySystem(@RequestBody SysMsgReq sysMsgReq) {
        return msgService.getMsgBySystem(sysMsgReq);
    }

    @ApiOperation(value = "添加好友")
    @PostMapping("/addFriend")
    public Result addFriend(@RequestBody SystemMsg systemMsg) {
        msgService.addFriend(systemMsg);
        return Result.ok();
    }

    @ApiOperation(value = "清空与系统消息")
    @GetMapping("/cleanAllSyStemMsg")
    public Result cleanAllSyStemMsg(String sysIds) {
        msgService.cleanAllSyStemMsg(sysIds);
        return Result.ok();
    }

    @ApiOperation(value = "清空与系统消息")
    @GetMapping("/cleanAllSyStemMsgAll")
    public Result cleanAllSyStemMsgAll(Integer userId) {
        msgService.cleanAllSyStemMsgAll(userId);
        return Result.ok();
    }

    @ApiOperation(value = "获取消息列表")
    @GetMapping("/getMsgs")
    public Result getMsgs(Integer userId) {
        List<MsgDto> msgDtos = msgService.getMsgs(userId);
        return Result.ok(msgDtos);
    }

    @PostMapping("/cleanMsgByFriend")
    @ApiOperation(value = "清空与好友的聊天记录")
    public Result cleanMsgByFriend(Integer userId) {
        List<MsgDto> msgDtos = msgService.getMsgs(userId);
        return Result.ok(msgDtos);
    }

    @GetMapping("/getNotReadMsg")
    @ApiOperation(value = "查询未读消息记录")
    public Result getNotReadMsg(Integer userId, Integer pageNum) {
        List<MsgReq> msgReqs = msgService.getNotReadMsg(userId, pageNum);
        return Result.ok(msgReqs);
    }

    @GetMapping("/getNotReadMsgByGroup")
    @ApiOperation(value = "查询未读消息记录")
    public Result getNotReadMsgByGroup(Integer userId, Integer pageNum) {
        List<MsgReq> msgReqs = msgService.getNotReadMsg(userId, pageNum);
        return Result.ok(msgReqs);
    }

    @GetMapping("/updateNotReadMsg")
    @ApiOperation(value = "更改未读消息状态")
    public Result updateNotReadMsg(Integer userId) {
        msgService.updateNotReadMsg(userId);
        return Result.ok();
    }

}
